#ifndef TEXTURE_H
#define TEXTURE_H

#include <SDL.h>
#include "Vector2i.h"
#include <string>
using namespace std;
#define KEYCOLOR 255, 0, 255

//!Represent a texture
class CTexture
{
private:
	//!Store the texture
	SDL_Surface* m_texture; 

	//!Width of the sprites contained by the texture
	int m_spriteWidth;

	//!Height of the sprites contained by the texture
	int m_spriteHeight;

	//!The number of sprite in the texture
	int m_nbOfSprite; 

	//!The number of sprite per row in the texture
	int m_nbOfSpritePerRow;

public:
	//!Constructor
	CTexture();

	//!Destructor
	~CTexture();

	//!Load a texture from a file.
	/*!
	\param filename Name of the texture file.
	\param spriteWidth Width of the sprite contained by the texture. Can be 0 if there is no sprite.
	\param spriteHeight Height of the sprite contained by the texture. Can be 0 if there is no sprite.
	\param nbOfSprite The number of sprite contained by the texture. Can be 0 if there is no sprite.
	\param nbOfSpritePerRow The number of sprite per row in the texture. Can be 0 if there is no sprite.
	\return True if the texture is loaded. False if it's not.
	*/
	bool loadTexture(const string& filename, int spriteWidth,	int spriteHeight,	int nbOfSprite, 
		int nbOfSpritePerRow);

	//!Load a texture from a buffer in memory.
	/*!
	\param buffer Buffer where the texture is stored.
	\param fileSize Size of the buffer.
	\param spriteWidth Width of the sprite contained by the texture. Can be 0 if there is no sprite.
	\param spriteHeight Height of the sprite contained by the texture. Can be 0 if there is no sprite.
	\param nbOfSprite The number of sprite contained by the texture. Can be 0 if there is no sprite.
	\param nbOfSpritePerRow The number of sprite per row in the texture. Can be 0 if there is no sprite.
	\return True if the texture is loaded. False if it's not.
	*/
	bool loadTextureFromMemory(char* buffer, int fileSize, int spriteWidth,	int spriteHeight,	int nbOfSprite, 
		int nbOfSpritePerRow);

	//!Display the texture
	/*!
	\param position The position where to display the texture
	\param screen The screen where the texture has to be displayed.
	*/
	void displayTexture(const CVector2i& position, SDL_Surface* screen)const;

	//!Display a sprite from the texture
	/*!
	\param position The position where to display the texture
	\param indexSprite The index of the sprite to display.
	\param screen The screen where the texture has to be displayed.
	*/
	void displaySprite(const CVector2i& position, int indexSprite, SDL_Surface* screen)const;

	//!Get the width of sprites
	/*!
	\return The width of sprites.
	*/
	int getSpriteWidth(void)const;

	//!Get the heighht of sprites
	/*!
	\return The height of sprites.
	*/
	int getSpriteHeight(void)const;

	//!Get the width of the texture
	/*!
	\return The width of the texture.
	*/
	int getTextureWidth(void)const;

	//!Get the height of the texture
	/*!
	\return The height of the texture.
	*/
	int getTextureHeight(void)const;

};
#endif
